<layout name="page" />
<block name="js">
	<div id="myModal" class="hidden">
		<div class="popup-frame" >
			<input type="hidden" name="ajax" id="ajax" value="1">
			<div class="popup-header">
				<div class="pull-left">
					<h1>设置查询密码</h1>
				</div>
				<div class="pull-right">
					<a id="btn_close" class="btn btn-return">关闭</a>
				</div>
			</div>
			<div class="popup-body">
				<div class="popup-body-scroll">
					<div class="popup-content">
						<form id="form_data" name="form_data" method="post" >
							<input type="hidden" name="opmode" id="opmode" value="edit">
							
								<label class="input-label" for="name">新密码*：</label>
								<div class="input-block col-16">
									<input class="input" type="password" id="password" name="password" check="required" info="请输入名称" >
								</div>
							</div>
							
								<label class="input-label" for="name">确认密码*：</label>
								<div class="input-block col-16">
									<input class="input" type="password" id="confirm_password" name="confirm_password" check="required" info="请输入名称" >
								</div>
							</div>
							
								<label class="input-label" for="name"></label>
								
									<a id="btn_save" class="btn" >确定</a>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		layui.use(['global'], function() {
			var $ = layui.jquery;
			var layer = layui.layer;

			$('#myModal').removeClass('hidden');
			var index = layer.open({
				type : 1,
				title : false,
				area : [560 + 'px', 460 + 'px'],
				shade : 0.6,
				closeBtn : 0,
				shadeClose : false,
				scrollbar : false,
				content : $('#myModal')
			});
			if (is_mobile()) {
				layer.full(index);
			}

			//保存后关闭
			$('#btn_save').on('click', function() {
				var msg = "";
				var vars = $("#form_data").serialize();
				new_pwd = $("#password").val();
				confirm_pwd = $("#confirm_password").val();
				if (new_pwd == confirm_pwd) {
					send_ajax("{:url('setpwd')}", vars, function(data) {
						window.location = "{:url('index')}";
					});
				} else {
					layer.msg("密码不一致");
				}
			});

			//关闭iframe
			$('#btn_close').click(function() {
				$('#myModal').addClass('hidden');
				layer.close(index);
			});

			$('#btn_select_pid').on('click', function() {
				winopen("{:url('winpop')}", 560, 470);
			});

			$(document).ready(function() {
				$("#password").keydown(function() {
					s = $(this).val();
					t = check_password(s);
					if (t == 0) {
						$("#msg").html("密码过短");
						$("#msg").css("color", "red");
					}
					if (t == 1) {
						$("#msg").html("密码强度差");
						$("#msg").css("color", "red");
					}
					if (t == 2) {
						$("#msg").html("密码强度良好");
						$("#msg").css("color", "blue");
					}
					if (t == 3) {
						$("#msg").html("密码强度高");
						$("#msg").css("color", "blue");
					}
				});
				$("#confirm_password").keyup(function() {
					new_pwd = $("#password").val();
					confirm_pwd = $(this).val();
					if (new_pwd != confirm_pwd) {
						$("#msg").html("密码不一致");
						$("#msg").css("color", "red");
					} else {
						$("#msg").html("密码一致");
						$("#msg").css("color", "blue");
					}
				});
			});
		});

		function check_password(s) {
			if (s.length < 4) {
				return 0;
			}
			var ls = 0;
			if (s.match(/[a-z]/ig)) {
				ls++;
			}
			if (s.match(/[0-9]/ig)) {
				ls++;
			}
			if (s.match(/(.[^a-z0-9])/ig)) {
				ls++;
			}
			if (s.length < 6 && ls > 0) {
				ls--;
			}
			return ls;
		}
 
	</script>
</block>
